package com.ctp.socket.base;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;

public class TcpClient {

	public static String[] connect(String param, int port) {
		try {
			Socket client = new Socket(host, port);

			InputStreamReader isr = new InputStreamReader(
					client.getInputStream(), "UTF-8");
			BufferedReader br = new BufferedReader(isr);

			OutputStreamWriter osw = new OutputStreamWriter(
					client.getOutputStream(), "UTF-8");
			PrintWriter pw = new PrintWriter(osw);

			pw.print(param);
			pw.flush();
			client.shutdownOutput();

			String line = br.readLine();
			client.shutdownInput();

			pw.close();
			br.close();
			client.close();

			return line.split(";");
		} catch (Exception e) {
			return null;
		}
	}

	private static final String host = "127.0.0.1";

}
